package com.example.controller;

import com.example.entity.RestBean;
import com.example.entity.singerAndGame.GameStatistics;
import com.example.service.GameStatisticsService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/statistics")
public class VoteStatisticsController {

    @Resource
    GameStatisticsService service;

    @PostMapping("/gid")
    public RestBean<List<GameStatistics>> getStatisticsGid(int gid) {
        return RestBean.success(service.getGameStatisticsByGid(gid));
    }

    @PostMapping("/add")
    public RestBean<String> add(int gid) {
        String s = service.addGameStatistics(gid);
        if (s == null) {
            return RestBean.success("比赛数据统计完成");
        } else {
            return RestBean.failure(400, s);
        }
    }

    @PostMapping("/delete")
    public RestBean<String> delete(int gid) {
        String s = service.deleteGameStatisticsByGid(gid);
        if (s == null) {
            return RestBean.success("比赛数据删除成功");
        } else {
            return RestBean.failure(400, s);
        }
    }

}
